package com.example.monitoringsystem.controller;

import com.example.monitoringsystem.bean.Doctor;
import com.example.monitoringsystem.bean.Patient;
import com.example.monitoringsystem.bean.User;
import com.example.monitoringsystem.service.AdminService;
import com.example.monitoringsystem.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @Autowired
    private UserService userService;

    //获得全部医生信息
    @GetMapping("/doctor/all/user")
    public List getAllDoctorUsers(){
        List<User> list;
        list=adminService.getAllDoctorUsers();
        return list;
    }

    //获得全部医生信息
    @GetMapping("/doctor/all/doctor")
    public List getAllDoctors(){
        List<Doctor> list;
        list=adminService.getAllDoctors();
        return list;
    }

    //添加医生或病人
    @PostMapping(value = "/insert",produces = "application/json; charset=utf-8")
    public String register(User user){
        System.out.println(user);
        if(userService.findUserByAccount(user.getAccount()) == null){
            adminService.register(user);
            return "添加成功";
        }
        else {
            return "该用户已存在";
        }
    }

    //修改医生信息
    @PostMapping(value = "/doctor/update",produces = "application/json; charset=utf-8")
    public String updateDoctor(User user,Doctor doctor){
        adminService.updateDoctor(user,doctor);
        return "更新成功";
    }

    //删除医生
    @PostMapping(value = "/doctor/delete",produces = "application/json; charset=utf-8")
    public String deleteDoctor(int doctorId){
        adminService.deleteDoctor(doctorId);
        return "删除成功";
    }

    //获得全部病人信息
    @GetMapping("/patient/all")
    public List getAllPatients(){
        List<Patient> list;
        list=adminService.getAllPatients();
        return list;
    }


//    //修改病人信息
//    @PostMapping(value = "/patient/update",produces = "application/json; charset=utf-8")
//    public String updatePatient(Patient patient){
//        adminService.updatePatient(patient);
//        return "更新成功";
//    }
    //修改病人信息
    @PostMapping(value = "/patient/update",produces = "application/json; charset=utf-8")
    public String updatePatient(User user){
        adminService.updatePatient(user);
        return "更新成功";
    }


    //删除病人
    @PostMapping(value = "/patient/delete",produces = "application/json; charset=utf-8")
    public String deletePatient(int patientId){
        adminService.deletePatient(patientId);
        return "删除成功";
    }

}
